﻿<UserControl x:Class="Samples.GasyTek.Lakana.Mvvm.Validation.DataAnnotation.SampleDataAnnotationValidationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:lakana="http://schemas.gasytek.com/wpf/lakana"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Loaded="UserControlLoaded">
    <UserControl.Resources>

        <Style x:Key="FieldTitleStyle"
               TargetType="TextBlock">
            <Setter Property="HorizontalAlignment"
                    Value="Right" />
            <Setter Property="VerticalAlignment"
                    Value="Top" />
            <Setter Property="Margin"
                    Value="0,0,5,0" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding HasChanged}"
                             Value="True">
                    <Setter Property="FontWeight"
                            Value="Bold" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <!-- Error template -->
        <ControlTemplate x:Key="ErrorTemplate">
            <DockPanel>
                <TextBlock DockPanel.Dock="Bottom"
                           Text="{Binding ErrorContent}"
                           Foreground="Red" 
                           FontSize="9"
                           FontFamily="Verdana" 
                           Margin="0,3,0,0"/>
                <AdornedElementPlaceholder />
            </DockPanel>
        </ControlTemplate>

    </UserControl.Resources>
    <DockPanel>
        <Border DockPanel.Dock="Top"
                Padding="10">
            <TextBlock Text="DataAnnotations Validation"
                       FontWeight="SemiBold"
                       FontSize="24" />
        </Border>
        <Border>
            <Grid VerticalAlignment="Center"
                  HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="30" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition MinHeight="50" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      MinWidth="120" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="180" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>

                <!--
            NOTE : {ui:Binding Code.Value} is strictly equivalent to 
                   {Binding Code.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=False}
        -->

                <!-- Code -->
                <TextBlock Text="{Binding Label}"
                           DataContext="{Binding Code}"
                           Style="{StaticResource FieldTitleStyle}" />
                <TextBox Grid.Column="2"
                         Text="{lakana:PropertyBinding Code.Value}"
                         Validation.ErrorTemplate="{StaticResource ErrorTemplate}" />
                <Image Grid.Column="4"
                       RenderOptions.BitmapScalingMode="HighQuality"
                       ToolTip="{Binding Code.Description}"
                       Source="../../Resources/info.png" />

                <!-- Age -->
                <TextBlock Grid.Row="2"
                           Text="{Binding Label}"
                           DataContext="{Binding Age}"
                           Style="{StaticResource FieldTitleStyle}" />
                <xctk:IntegerUpDown Grid.Row="2"
                                    Grid.Column="2"
                                    Value="{lakana:PropertyBinding Age.Value}"
                                    AllowSpin="True"
                                    Validation.ErrorTemplate="{StaticResource ErrorTemplate}" />
                <Image Grid.Row="2"
                       Grid.Column="4"
                       RenderOptions.BitmapScalingMode="HighQuality"
                       ToolTip="{Binding Age.Description}"
                       Source="../../Resources/info.png" />

                <!-- Country -->
                <TextBlock Grid.Row="4"
                           Text="{Binding Label}"
                           DataContext="{Binding Country}"
                           Style="{StaticResource FieldTitleStyle}" />
                <ComboBox Grid.Row="4"
                          Grid.Column="2"
                          ItemsSource="{Binding Country.ItemsSource}"
                          SelectedItem="{lakana:PropertyBinding Country.SelectedValue}"
                          DisplayMemberPath="Name"
                          Validation.ErrorTemplate="{StaticResource ErrorTemplate}" />
                <Image Grid.Row="4"
                       Grid.Column="4"
                       RenderOptions.BitmapScalingMode="HighQuality"
                       ToolTip="{Binding Country.Description}"
                       Source="../../Resources/info.png" />

                <!-- Rank -->
                <TextBlock Grid.Row="6"
                           Text="{Binding Label}"
                           DataContext="{Binding Rank}"
                           Style="{StaticResource FieldTitleStyle}" />
                <ComboBox Grid.Row="6"
                          Grid.Column="2"
                          ItemsSource="{Binding Rank.ItemsSource}"
                          SelectedValue="{lakana:PropertyBinding Rank.SelectedValue}"
                          SelectedValuePath="Value"
                          DisplayMemberPath="Label"
                          Validation.ErrorTemplate="{StaticResource ErrorTemplate}" />
                <Image Grid.Row="6"
                       Grid.Column="4"
                       RenderOptions.BitmapScalingMode="HighQuality"
                       ToolTip="{Binding Rank.Description}"
                       Source="../../Resources/info.png" />

                <!-- Save / Cancel buttons -->
                <Border Grid.Row="8"
                        Grid.ColumnSpan="5">
                    <StackPanel>
                        <StackPanel HorizontalAlignment="Right"
                                    Orientation="Horizontal">
                            <Button Content="Save"
                                    Width="120"
                                    Command="{Binding SaveCommand}" />
                            <Button Content="Cancel"
                                    Width="80"
                                    Margin="6,0,0,0"
                                    Command="{Binding CancelCommand}" />
                        </StackPanel>
                    </StackPanel>
                </Border>
            </Grid>
        </Border>
    </DockPanel>
</UserControl>
